package com.clkj.nangang.mvp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.clkj.nangang.R;
import com.clkj.nangang.mvp.model.NewsModel;

import java.util.List;

/**
 * Created by Administrator on 2017/8/4.
 */

public class NewsListAdapter extends BaseAdapter {

    private Context context;
    private List<NewsModel> newsModelList;

    public NewsListAdapter(Context context, List<NewsModel> newsModelList) {
        this.context = context;
        this.newsModelList = newsModelList;
    }

    @Override
    public int getCount() {
        return newsModelList.size();
    }

    @Override
    public Object getItem(int position) {
        return newsModelList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        localViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_newslist, null);
            holder = new localViewHolder();

            holder.tvTitle = (TextView) convertView.findViewById(R.id.tv_title);
            holder.tvTime = (TextView) convertView.findViewById(R.id.tv_time);

            convertView.setTag(holder);
        } else {
            holder = (localViewHolder) convertView.getTag();
        }

        holder.tvTitle.setText(newsModelList.get(position).getTitle());
        holder.tvTime.setText(newsModelList.get(position).getFBTime());

        return convertView;
    }

    class localViewHolder {

        private TextView tvTitle, tvTime;
    }

}
